{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.9 64-bit",
   "metadata": {
    "interpreter": {
     "hash": "0600588c3b5f4418cbe7b5ebc6825b479f3bc010269d8b60d75058cdd010adfe"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from stack import Stack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 进制转换\n",
    "def convert(decNumber, base):\n",
    "    \"\"\"进制转换，将10进制数转换为目标进制（16进制以下）\"\"\"\n",
    "    digits = \"0123456789ABCDEF\"\n",
    "    remstack = Stack()\n",
    "    while decNumber > 0:\n",
    "        remstack.push(decNumber % base)\n",
    "        decNumber = decNumber // base\n",
    "        pass\n",
    "    \n",
    "    newString = \"\"\n",
    "    while not remstack.isEmpty():\n",
    "        newString = newString + digits[remstack.pop()]\n",
    "\n",
    "    return newString"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "E9\n"
     ]
    }
   ],
   "source": [
    "print(convert(233, 16))"
   ]
  }
 ]
}